package com.sikaryofficial.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.domain.dto.req.UserActionListReq;
import com.sikaryofficial.backend.domain.dto.req.UserActionReq;
import com.sikaryofficial.backend.domain.dto.resp.UserActionListResp;
import com.sikaryofficial.backend.manager.UserActionManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.system.api.model.UserPointResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户行为Controller
 *
 * @author qinjinyuan
 * @date 2023-11-09
 */
@RestController
@RequestMapping("/user/action")
@Api(tags = "用户行为(点赞,收藏,转发)")
@SuppressWarnings(value = "unchecked")
public class UserActionController extends BaseController {
    @Autowired
    private UserActionManager userActionManager;

    /**
     * 新增用户行为
     */
    @PostMapping("/save")
    @ApiOperation("保存用户行为")
    public R<UserPointResultVO> save(@Validated @RequestBody UserActionReq req) {
        return R.ok(userActionManager.userActionSave(req));
    }

    /**
     * 我点赞-收藏-转发列表
     *
     * @param req 分页参数
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("我点赞-收藏-转发列表-个人中心")
    public PageResult<UserActionListResp> listPage(@Validated  @RequestBody UserActionListReq req) {
        IPage<UserActionListResp> result = (IPage<UserActionListResp>) userActionManager.listPage(req);
        return PageUtil.success(result.getRecords(), result.getTotal());
    }
}
